<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>拖拽打分</title>
    <style>
.range{width: 500px;height: 30px;background-color: #ccc;margin:0 30px;position: relative}
.box{width: 0px;height: 30px;background-color: pink;}
.ctrl{width: 20px;height: 40px;background-color: hotpink;position: absolute;top:-5px;left:-10px;} 
.content{display:flex;justify-content: center;}
.num{width: 50px;padding:10px;border:1px solid red;}
    
.range1{width: 500px;height: 30px;background-color: #ccc;margin:0 30px;position: relative}
.box1{width: 0px;height: 30px;background-color: pink;}
.ctrl1{width: 20px;height: 40px;background-color: black;position: absolute;top:-5px;left:-10px;} 
.content1{display:flex;justify-content: center;}
.num1{width: 50px;padding:10px;border:1px solid red;}   
    
.range2{width: 500px;height: 30px;background-color: #ccc;margin:0 30px;position: relative}
.box2{width: 0px;height: 30px;background-color: pink;}
.ctrl2{width: 20px;height: 40px;background-color: yellow;position: absolute;top:-5px;left:-10px;} 
.content2{display:flex;justify-content: center;}
.num2{width: 50px;padding:10px;border:1px solid red;}    
    
    
    
    
    
    
    
    
    
    
    </style>
</head>
<body>
    <div class="content">
        <div class="num">0</div>
        <div class="range">  <!-- range:浮动条。 -->
            <div class="box"></div>
            <div class="ctrl"></div>
        </div>       
        <div class="num" id="result">100</div>
    </div>


    <div class="content1">
        <div class="num1">0</div>
        <div class="range1">  <!-- range:浮动条。 -->
            <div class="box1"></div>
            <div class="ctrl1"></div>
        </div>       
        <div class="num" id="result1">100</div>
    </div>



    <div class="content2">
        <div class="num2">0</div>
        <div class="range2">  <!-- range:浮动条。 -->
            <div class="box2"></div>
            <div class="ctrl2"></div>
        </div>       
        <div class="num" id="result2">100</div>
    </div>

    
</body>
<script>
    function $(ele){
        return document.querySelector(ele);
    }
    function move(e){
        e=e || window.event;
        let x=e.clientX-$('.range').offsetLeft-10; //offsetLeft:距离页面的左边距。
        x=x>500 ? 500 : x;
        x=x<0 ? 0 : x;
        $('.ctrl').style.left=x+'px';
        $('.box').style.left=x+'px';
        $('#result').innerText = x/5;
    }

    $('.ctrl').onmousedown=function(){
        document.addEventListener('mousemove',move,false)
    }


    $('.ctrl').onmouseup=function(){
        document.addEventListener('mousemove',move,false)
    }

    function $(ele){
        return document.querySelector(ele);
    }
    function move(e){
        e=e || window.event;
        let x=e.clientX-$('.range1').offsetLeft-10; //offsetLeft:距离页面的左边距。
        x=x>500 ? 500 : x;
        x=x<0 ? 0 : x;
        $('.ctrl1').style.left=x+'px';
        $('.box1').style.left=x+'px';
        $('#result1').innerText = x/5;
    }

    $('.ctrl1').onmousedown=function(){
        document.addEventListener('mousemove',move,false)
    }


    $('.ctrl1').onmouseup=function(){
        document.addEventListener('mousemove',move,false)
    }

    function $(ele){
        return document.querySelector(ele);
    }
    function move(e){
        e=e || window.event;
        let x=e.clientX-$('.range2').offsetLeft-10; //offsetLeft:距离页面的左边距。
        x=x>500 ? 500 : x;
        x=x<0 ? 0 : x;
        $('.ctrl2').style.left=x+'px';
        $('.box2').style.left=x+'px';
        $('#result2').innerText = x/5;
    }

    $('.ctrl2').onmousedown=function(){
        document.addEventListener('mousemove',move,false)
    }


    $('.ctrl2').onmouseup=function(){
        document.addEventListener('mousemove',move,false)
    }
</script>
</html>